<?php

    function connect($config)
    {
      try  
      {
          $connection =
          new PDO($config['driver'].":host=".
          $config['host'].";dbname=".
          $config['dbname'], $config['user'], $config['pass']);
          
          return $connection;  
      }
      catch(PDOException $e)
      {
         return false;
      }
        
    }
    
    function insertquery ($queryString,$connection,$mask)
    {
        try
        {
        $state = $connection->prepare($queryString);
        $state->execute($mask);
        }
        catch(PDOException $e)
        {
         return false;
        }
    }
    
 /*--------------------------------------------------------*/   
    
    function query($queryString, $bindParam, $connection)
    {
        $state = $connection->prepare($queryString);
        $state->execute($bindParam);
        $res = $state->fetchAll();
        if($res)
            return $res;
        else
            return false; 
        
        //if($state->rowCount() > 0)
        //    return $state;
        //else
        //return false;    
    }
    
    function getAllPosts($connection,$querystr)
    {
      try  
      {
         $state =  $connection->query($querystr);
           if($state->rowCount() > 0)
            return $state->fetchAll();
           else
            return false;    
      }
      catch(PDOException $e)
      {
         return false;
      } 
    }
    
    
   function getPostById($id, $connection)
    {
        $result = query("SELECT * FROM article WHERE ArticleID = :id LIMIT 1",
        array('id'=>$id), $connection);
        if($result)
          return $result[0];
    }

    
//_______________ SHOW MENu___

       function showmenu ($resQuery,$servget,$servurl,$servname,$classul)
       {
        $ct = count($resQuery);
          echo "<ul class='".$classul."'>";
          for ($i=0; $i<$ct; $i++)
          {    
              echo "<li><a href='http://lsc/$servget/".$resQuery[$i][$servurl]."'>".$resQuery[$i][$servname]."</a></li>";
           }
          echo "</ul>";
        
       }
 
    
    
    
    


?>